﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using ERF;

namespace ERF.Input
{
    public class MouseDevice : AnalogDevice
    {
        private const float MOUSE_SENSITIVITY = 600f;

        public enum MouseTypes
        {
            AIM,
            POINTER
        }
        private Game game;
        private MouseTypes currentType;

        public MouseTypes CurrentType
        {
          get { return currentType; }
          set { currentType = value; }
        }

        public MouseDevice(InputHandler handler, Game game, MouseTypes currentType)
            : base(handler)
        {
            this.currentType = currentType;
            this.game = game;
        }

        public override Vector2 Location
        {
            get {
                Vector2 location = new Vector2(handler.MouseState.X, handler.MouseState.Y);
                
                if (currentType == MouseTypes.AIM)
                {
                    Vector2 oldLocation = new Vector2(handler.OldMouseState.X, handler.OldMouseState.Y);

                    Vector2 mouseResetPosition = new Vector2(game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height) / 2f;
                    if(game.IsActive)
                        Mouse.SetPosition((int)mouseResetPosition.X, (int)mouseResetPosition.Y);

                    return (location - mouseResetPosition) / MOUSE_SENSITIVITY;
                }

                return location;
            }
        }
    }
}
